package eu.news.template;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import eu.jk.web.template.Filler;

public class WebPage {
	Map<String,Object> parameters;
	String template;
	
	public WebPage(String template){
		this.template=template;
		parameters=new HashMap<String, Object>();
	}
	
	public void setParameter(String name,Object value){
		parameters.put(name, value);
	}
	
	public Object removeParameter(String name){
		return parameters.remove(name);
	}
	
	public void setTemplate(String template){
		this.template=template;
	}
	
	public String generateHtml(){
		return Filler.fill(template,parameters);
	}
	
	public void flushToResponse(HttpServletResponse response) throws IOException{
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print(generateHtml());
	}
}
